﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using IBupro.Models.Classes;
using iBuproModel;

namespace IBupro.Models
{
    public class DepartmentModel : CustomModel
    {
        public DepartmentModel(Department department)
        {
            this.Department = department;
        }

        public DepartmentModel() {}

        public Department Department { get; set; }
        public List<string> ActualPrincipals;
        public List<string> ActualAdministrators;

        public MultiSelectList MultiSelectListPrincipals()
        {
            this.ActualPrincipals = Department.DepartmentPrincipal.Select(principal => principal.Id.ToString()).ToList();
            
            var userRepository = repositoryService.UserRepositoryCreateInstance();

            IEnumerable principals = from r in userRepository.GetAll().ToList()
                                select new {Id = r.Id, Name = r.LastName + " " + r.FirstName + ", " + r.Username};

            return new MultiSelectList(principals, "Id", "Name", ActualPrincipals);
        }
        
        public IEnumerable<int> SelectedPrincipals { get; set; }

        public MultiSelectList MultiSelectListAdministrators()
        {
            this.ActualAdministrators = Department.DepartmentAdministrators.Select(admin => admin.Id.ToString()).ToList();

            var userRepository = repositoryService.UserRepositoryCreateInstance();

            // pokud vybere uzivatele ktery je jiz administratorem jine katedry, vyhodi repositar vyjimku
            IEnumerable administrators = from r in userRepository.GetAll().ToList()
                                select new { Id = r.Id, Name = r.LastName + " " + r.FirstName + ", " + r.Username };

            return new MultiSelectList(administrators, "Id", "Name", ActualAdministrators);
        }

        public IEnumerable<int> SelectedAdministrators { get; set; }
    }
}